/**
 * 关于我们
 */
define(function (require) {
    var $ = require('jquery');
    var base = require('base');
    var com = require('./common');

    if(localStorage.getItem("lang")){
		var Lang = localStorage.getItem("lang")
	}else{
		var Lang = "zh_CN"
	}

	// 获取网站配置信息
	$.ajax(seajs.ajaxroot + "getConfig",{
		type:'post',		
		headers:{
			'locale-language': Lang,
            "Content-Type":"multipart/form-data"
		}, 
		success:function(res){
			console.log("baseConfig:", res)
			let baseConfig = res.data
            $('#about_amway_title').html(baseConfig.about_amway.title)
            $('#about_amway_content').html(baseConfig.about_amway.content)

            let visions_img = '<img src='+baseConfig.visions_img+' class="_full" alt="">';
            $('#visions_img').html(visions_img)
            $('#visions_title').html(baseConfig.visions_title)
            $('#visions_description').html(baseConfig.visions_description)

            let mission_img = '<img src='+baseConfig.mission_img+' class="_full" alt="">';
            $('#mission_img').html(mission_img)
            $('#mission_title').html(baseConfig.mission_title)
            $('#mission_description').html(baseConfig.mission_description)
            
            let values_img = '<img src='+baseConfig.values_img+' class="_full" alt="">';
            $('#values_img').html(values_img)
            $('#values_title').html(baseConfig.values_title)
            $('#values_description').html(baseConfig.values_description)

		}
	})
    


    // 发展历程
	$.ajax(seajs.ajaxroot + "getHistory", {
		type: 'post',
        async:false,
		headers:{
			'locale-language':Lang
		},
		success:function(res){			
            let developing = res.data
            let htmlData = '<ul>';
            let htmlData2 = '';
            
            developing.forEach((item, index)=>{
                if(index == 0){
                    htmlData += '<li style="display: list-item;">'
                }else{
                    htmlData += '<li style="display: none;">'
                }
                htmlData += '<div class="time">'+item.year+'</div>';
                htmlData += '<div class="name">'+item.title+'</div>';
                // htmlData += '<div class="time2">'+item.year+'</div>';
                htmlData += '</li>'
        
                // 时间轴
                htmlData2 += '<li class="swiper-slide"><div>'+item.year+'</div></li>'
            })
            htmlData += '</ul>';
            $("#develop").html(htmlData);
            $("#time_axis").html(htmlData2);
            
		}
	})









    function swiperFun(swiper) {
        this.dom = swiper.dom;
        this.domList = this.dom;
        this.dom.find('ul').addClass('swiper-wrapper');
        this.dom.find('li').addClass('swiper-slide');
        if (swiper.domList !== undefined) {
            this.domList = this.dom.find(swiper.domList)
        }
        if (this.dom.find('.num').length > 0) {
            this.dom.find('.num-total').html(this.dom.find('li').length)
        }

        this.change = function () { };
        var that = this;
        this.mySwiper = new Swiper(that.domList, {
            direction: swiper.direction !== undefined ? swiper.direction : 'horizontal',
            effect: swiper.effect !== undefined ? swiper.effect : 'slide',
            loop: swiper.loop !== undefined ? swiper.loop : true,
            autoplay: swiper.autoplay !== undefined ? swiper.autoplay : 5000,
            autoplayDisableOnInteraction: false,
            paginationClickable: true,
            speed: 600,
            slidesPerView: swiper.slidesPerView !== undefined ? swiper.slidesPerView : 1,
            centeredSlides: swiper.centeredSlides !== undefined ? swiper.centeredSlides : false,
            pagination: that.dom.find('.dots'),
            roundLengths: true,
            onSlideChangeStart: function (swiper) {
                if (that.dom.find('.num').length > 0) {
                    that.dom.find('.num-curr').html(swiper.realIndex + 1)
                }
                that.change(swiper.realIndex);
            }
        });
        /*this.dom.hover(
            function () {
                that.mySwiper.stopAutoplay()
            },
            function () {
                that.mySwiper.startAutoplay()
            }
        );*/
        this.dom.find('.prev').click(function () {
            that.mySwiper.slidePrev();
            return false
        });
        this.dom.find('.next').click(function () {
            that.mySwiper.slideNext();
            return false
        })
    }







    $(function () {
        let dom = $('.about-3'),
            li = dom.find('.list li'),
            line = dom.find('.line'),
            curr = 0,
            view = 9,
            btn = dom.find('.list2 li');

        if ($(window).width() < 800) {
            view = 4
        }
        let swiper = new swiperFun({
            dom: dom.find('.list2'),
            domList: '.list-wrapper',
            slidesPerView: view,
            loop: false,
            autoplay: false
        });
        dom.find('.prev').click(function () {
            swiper.mySwiper.slidePrev();
            if (curr > 0) {
                curr--
            }
            change();
            return false
        });
        dom.find('.next').click(function () {
            swiper.mySwiper.slideNext();
            if (curr < li.length - 1) {
                curr++
            }
            change();
            return false
        });
        btn.each(function (i) {
            $(this).click(function () {
                curr = i;
                change()
            })
        });
        change();
        function change() {
            li.hide();
            li.eq(curr).fadeIn(300);
            btn.removeClass('on');
            btn.eq(curr).addClass('on')
        }
    })




})